﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WineStore.DAL;
using WineStore.Models;
using System.Data;
using PagedList;
using PagedList.Mvc;
using System.Data.Entity;

namespace WineStore.Controllers
{

    public class OrderDetailController : Controller
    {
        // GET: /OrderDetail/ShowOrderDetail/
        public ViewResult ShowOrderDetail(int orderId,int? page)
        {
            ViewBag.OrderId = null;
            using (var db = new WineDbContext())
            {
                ViewBag.OrderId = orderId;
                var orderdetail = db.OrderDetails.Where(o=>o.OrderId==orderId).Include(o => o.Product)
                    .OrderByDescending(o => o.OrderDetailId);

                int pageSize = 50;
                int pageNumber = (page ?? 1);

                // Thiet lap thuoc tinh khi phan trang
                PagedListRenderOptions pro = new PagedListRenderOptions();
                pro.MaximumPageNumbersToDisplay = 5;
                pro.LinkToLastPageFormat = "Last";
                pro.DisplayLinkToLastPage = true;
                pro.LinkToFirstPageFormat = "First";
                pro.DisplayLinkToFirstPage = true;
                pro.LinkToNextPageFormat = ">>";
                pro.DisplayLinkToNextPage = true;
                pro.LinkToPreviousPageFormat = "<<";
                pro.DisplayLinkToPreviousPage = true;

                ViewBag.Pro = pro;

                return View(orderdetail.ToPagedList(pageNumber, pageSize));
            }
        }

    }
}
